//
//  RBURLConfig.m
//  RBDemoProj
//
//  Created by Lan on 2018/2/11.
//  Copyright © 2018年 SummerTea. All rights reserved.
//

#import "RBURLConfig.h"
#import "RBDefine.h"

/*==========online start==========*/
static NSString *const RB_ONLINE_COMMON_SERVICE_BASE_URL = @"";
static NSString *const RB_ONLINE_COMMON_SERVICE_PIC_URL = @"";
static NSString *const RB_ONLINE_XX_SERVICE_BASE_URL = @"";
static NSString *const RB_ONLINE_XX_SERVICE_PIC_URL = @"";
/*==========online end==========*/

/*==========test start==========*/
static NSString *const RB_TEST_COMMON_SERVICE_BASE_URL = @"http://dxm56.zihai.shop";
static NSString *const RB_TEST_COMMON_SERVICE_PIC_URL = @"http://dxm56.zihai.shop";
static NSString *const RB_TEST_XX_SERVICE_BASE_URL = @"";
static NSString *const RB_TEST_XX_SERVICE_PIC_URL = @"";
/*==========test end==========*/

/*==========QA start==========*/
static NSString *const RB_QA_COMMON_SERVICE_BASE_URL = @"";
static NSString *const RB_QA_COMMON_SERVICE_PIC_URL = @"";
static NSString *const RB_QA_XX_SERVICE_BASE_URL = @"";
static NSString *const RB_QA_XX_SERVICE_PIC_URL = @"";
/*==========QA end==========*/

@implementation RBURLConfig

+ (instancetype)shareInstance
{
    static RBURLConfig *instance = nil;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        instance = [self new];
        instance.currentEnvironment = kCurrentEnvironment;
    });
    return instance;
}

- (NSString *)commonServiceBaseUrl
{
    switch (self.currentEnvironment)
    {
        case RBURLEnvironmentOnline:
            return RB_ONLINE_COMMON_SERVICE_BASE_URL;
            break;
        case RBURLEnvironmentTest:
            return RB_TEST_COMMON_SERVICE_BASE_URL;
            break;
        case RBURLEnvironmentQA:
            return RB_QA_COMMON_SERVICE_BASE_URL;
            break;
        default:
            return @"";
            break;
    }
}

- (NSString *)commonServicePicUrl
{
    switch (self.currentEnvironment)
    {
        case RBURLEnvironmentOnline:
            return RB_ONLINE_COMMON_SERVICE_PIC_URL;
            break;
        case RBURLEnvironmentTest:
            return RB_TEST_COMMON_SERVICE_PIC_URL;
            break;
        case RBURLEnvironmentQA:
            return RB_QA_COMMON_SERVICE_PIC_URL;
            break;
        default:
            return @"";
            break;
    }
}

- (NSString *)xxServiceBaseUrl
{
    switch (self.currentEnvironment)
    {
        case RBURLEnvironmentOnline:
            return RB_ONLINE_XX_SERVICE_BASE_URL;
            break;
        case RBURLEnvironmentTest:
            return RB_TEST_XX_SERVICE_BASE_URL;
            break;
        case RBURLEnvironmentQA:
            return RB_QA_XX_SERVICE_BASE_URL;
            break;
        default:
            return @"";
            break;
    }
}

- (NSString *)xxServicePicUrl
{
    switch (self.currentEnvironment)
    {
        case RBURLEnvironmentOnline:
            return RB_ONLINE_XX_SERVICE_PIC_URL;
            break;
        case RBURLEnvironmentTest:
            return RB_TEST_XX_SERVICE_PIC_URL;
            break;
        case RBURLEnvironmentQA:
            return RB_QA_XX_SERVICE_PIC_URL;
            break;
        default:
            return @"";
            break;
    }
}

+ (NSString *)pathWithService:(NSInteger)service fileName:(NSString *)fileName
{
    NSString *domain = [[self shareInstance] commonServiceBaseUrl];
    if (![domain hasSuffix:@"/"] && ![fileName hasPrefix:@"/"])
    {
        fileName = [@"/" stringByAppendingString:fileName];
    }
    return [domain stringByAppendingString:fileName];
}

+ (NSString *)adjustImageUrl:(NSString *)url
{
    if ([url hasPrefix:@"http"])
    {
        return url;
    }
    else
    {
        NSString *domain = [[self shareInstance] commonServicePicUrl];
        NSString *fileName = kRBNotNilString(url);
        if (![domain hasSuffix:@"/"] && ![fileName hasPrefix:@"/"])
        {
            fileName = [@"/" stringByAppendingString:fileName];
        }
        return [domain stringByAppendingString:fileName];
    }
}

@end
